home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
187_01
/
showch.c
< prev
next >
Wrap
Text File
|
1985-12-29
|
2KB
|
59 lines
/*@*****************************************************/
/*@ */
/*@ showch - display a character on the screen. */
/*@ The character is displayed normally, if */
/*@ possible, displayed as a reverse video */
/*@ name (e.g. NUL for 0x00), if appropriate, */
/*@ or displayed as \xxx\ where xxx is the */
/*@ decimal value of the character. */
/*@ */
/*@ Usage: showch(ch); */
/*@ where ch is a character. */
/*@ */
/*@ Returns the number of screen positions used to */
/*@ display the character. */
/*@ */
/*@*****************************************************/
#define EOS '\0'
#define REVVID 0x70 /* reverse video attribute */
#define NORM 0x07 /* normal video attribute */
int
showch(c)
char c;
{
static char *cntlchr[] = {"NUL","SOH","STX","ETX","EOT","ENQ","ACK","BEL",
"BS ","HT ","LF ","VT ","FF ","CR ","SO ","SI ","DLE",
"DC1","DC2","DC3","DC4","NAK","SYN","ETB","CAN","EM ",
"SUB","ESC","FS ","GS ","RS ","US "};
int ret, strbuf[4];
ret = 0;
if ((c >= 0) && (c <= 31)) { /* HANDLE CONTROL CHARS */
ret = 3; /* number of positions used */
conout(cntlchr[(int)c],REVVID);
}
else if ((c >= ' ') && (c <= '~')) { /* HANDLE NORMAL CHARS */
ret = 1; /* number of positions used */
strbuf[0] = c; /* display as normal video */
strbuf[1] = EOS;
conout(strbuf,NORM);
}
else if (c == 127) { /* HANDLE 0X7F (DEL) */
ret = 3; /* number of positions used */
conout("DEL",REVVID);
}
else { /* HANDLE FUNNY CHARS */
conout("\\",REVVID);
itoa(c,strbuf);
conout(strbuf,REVVID);
conout("\\",REVVID);
ret = strlen(strbuf) + 2; /* number of positions used */
}
conout(" ",NORM); /* separate displays */
return(++ret);
}